package _6funcs

// defer方法类似栈，先进后出，先定义的后执行
func Defer() {
	defer func() {
		println("第一个 defer")
	}()

	defer func() {
		println("第二个 defer")
	}()
}

func DeferClosure() {
	i := 0
	defer func() {
		println(i)
	}()
	i = 1

}

func DeferClosureV1() {
	i := 0
	defer func(a int) {
		println(a)
	}(i)
	i = 1
}

func DeferReturn() int {
	a := 0
	defer func() {
		a = 1
	}()
	return a
}

// 返回值带名字，该值会被修改
func DeferReturnV1() (a int) {
	a = 0
	defer func() {
		a = 1
		println(a)
	}()
	return a
}
